package org.groupg.poi.excel;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class ExcelProcessor {
    public static void processExcelFile(String inputFilePath, String outputFilePath, String placeholder, String replacement) {
        try (FileInputStream fis = new FileInputStream(inputFilePath);
             Workbook workbook = new XSSFWorkbook(fis);
             FileOutputStream fos = new FileOutputStream(outputFilePath)) {
            for (Sheet sheet : workbook) {
                for (Row row : sheet) {
                    for (Cell cell : row) {
                        if (cell.getCellType() == CellType.STRING) {
                            String cellValue = cell.getStringCellValue();
                            cellValue = cellValue.replaceAll(placeholder, replacement);
                            cell.setCellValue(cellValue);
                        }
                    }
                }
            }
            workbook.write(fos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}